<script setup>
import { ref, onMounted } from "vue";
import axios from 'axios';
import { useRouter } from 'vue-router';
import { useStore } from 'vuex';

const router = useRouter();
const store = useStore();
let user = ref({
  "userId":"",
  "username":"系统名字",
  "email":"",
  "passwordHash":"",
  "fullName":"",
  "birthdate":"",
  "registrationDate":"",
  "lastLoginDate":"",
  "profilePicture":"",
  "status":"",
  "phone":"13812345678",
  "province":"未知",
  "info":""
});
let notes = ref([]);
let datainit=()=>{
  axios.post('/admin/users/findByPhone',user.value)
      .then(response => {
        user.value = response.data.date;
        store.dispatch('updateUser', user.value);
        console.log(user.value.userId);
        noteinit();
      });
}
let noteinit=()=>{
  axios.post('/admin/notes/getNoteByUserId',{userId: user.value.userId}).then(res=>{
    notes.value = res.data.date;
  });
}
onMounted(()=>{
  datainit();
  sharedData.value = user.value;
});
const sharedData = ref('这是共享的数据');
provide('sharedData', sharedData);
</script>

<template>
  <van-row>
    <van-col span="4">
      <router-link to="/setting" style="color: #333333">
        <img src="../../../assets/Setting.png" alt="设置" />
      </router-link>
    </van-col>
    <van-col span="16"></van-col>
    <van-col span="4" align="right">
      <router-link to="/release" style="color: #333333">
        <img src="../../../assets/Release.png" alt="发布" />
      </router-link>
    </van-col>
  </van-row>
  <van-row class="first-row">
    <van-col span="16" style="margin-top: 15px">
      <div class="name" :vocab="user.username">{{ user.username }}</div><br />
      <div class="ip-location" :vocab="user.province">IP属地: {{ user.province }}</div>
    </van-col>
    <van-col span="8" align="right">
      <img :style="{ width: '20vw' }" :src="user.profilePicture" alt="头像" />
    </van-col>
  </van-row>
  <van-row style="margin-top: 10px">
    <van-col span="24">
      <img :style="{ width: '100vw' }" src="../../../assets/vip.png" alt="VIP" />
    </van-col>
  </van-row>
  <van-row style="margin-top: 10px; align-items: center">
    <van-col span="6" align="center">
      <router-link to="/notes" style="color: #333333">
      <div class="stats">
        <span class="value">{{ notes.length }}</span>
        <br />
        <span class="title">笔记</span>
      </div>
        </router-link>
    </van-col>
    <van-col span="6" align="center">
      <span class="value">0</span>
      <br />
      <span class="title">收到的赞</span>
    </van-col>
    <van-col span="6" align="center">
      <router-link to="/follow" style="color: #333333">
        <span class="value">0</span>
        <br />
        <span class="title">关注</span>
      </router-link>
    </van-col>
    <van-col span="6" align="center">
      <router-link to="/fans" style="color: #333333">
        <span class="value">0</span>
        <br />
        <span class="title">粉丝</span>
      </router-link>
    </van-col>
  </van-row>
  <router-link to="/release">
  <img :style="{ width: '100vw' }" src="../../../assets/notes.png" alt="笔记">
  </router-link>
</template>

<style scoped>
.profile-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  margin: 0;
  font-family: Arial, sans-serif;
}

.header {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 20px;
  margin-bottom: 20px;
}

.avatar {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background-color: gray;
}

.name {
  font-size: 24px;
  color: #333;
}

.ip-location {
  font-size: 14px;
  color: #999;
}
.title {
  font-size: 14px;
  color: #999;
}

.upgrade-button {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 40px;
  background-color: #333333;
  color: white;
  border: none;
  border-radius: 5px;
  padding: 5px 10px;
  cursor: pointer;
}

.calendar-container {
  width: 100%;
  max-width: 300px;
  margin-top: 20px;
}

.day {
  list-style-type: none;
  text-align: center;
  font-weight: bold;
  font-size: 14px;
  width: calc(100% / 7);
  float: left;
  height: 30px;
  line-height: 30px;
  border-bottom: 1px solid #ccc;
}

.calendar-message {
  text-align: center;
  font-size: 16px;
  margin-top: 10px;
}

.bottom-bar {
  display: flex;
  justify-content: space-between;
  width: 100%;
  max-width: 300px;
  margin-top: 20px;
}

.tab-item {
  display: inline-block;
  width: calc(100% / 4 - 10px);
  text-align: center;
  font-size: 16px;
  color: #666;
  cursor: pointer;
  transition: color 0.3s ease-in-out;
}

.active {
  color: #007bff !important;
}

</style>